import {createRouter, createWebHistory, onBeforeRouteLeave} from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'nav',
      component: () => import('../views/NavigationPage/lead-page.vue'), 

      // onBeforeRouteLeave: (to,from,next) => {
      //   const link = document.querySelector('link[href="src/assets/NavigationPage/index.css"]')
      //   if (link){
      //     link.parentNode.removeChild(link)
      //   }
      //   next();
      // }
    },
    {
      path: '/index',
      name: 'main',
      component: () => import('../views/MainPage/main-container.vue'),
      children:[
        {
          path:'',
          name:'main-show',
          component:()=>import('../views/ProductPage/main-show.vue')
        },
        {
          path:'product',
          name:'product',
          component:()=>import('../views/ProductPage/main-product.vue')
        },
        {
          path:'info',
          name:'picinfo',
          component:()=>import('../views/ProductPage/main-info.vue')
        },
        {
          path:'order',
          name:'order',
          component:()=>import('../views/orders.vue')
        },
        {
          path:'carts',
          name:'carts',
          component:()=>import('../components/common/cart.vue')
        },
        {
          path:'account',
          name:'myAccount',
          component:()=>import('../views/AccountPage/account-page.vue')
        },
        {
          //新建订单页面
          path:'new-order',
          name:'new-order',
          component:()=>import('../views/OrderPage/new-order.vue'),
        },
        {
          //查看订单页面
          path:'view-order',
          name:'view-order',
          component:()=>import('../views/OrderPage/view-order.vue'),
        },
        {
          //确认订单页面
          path:'confirm-order',
          name:'confirm-order',
          component:()=>import('../views/OrderPage/confirm-order.vue'),
        }
      ]
    },
    {
      // 登录页面
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/login.vue')
    },
    {
      path: '/register',
      name: 'register',
      component:()=>import('../views/Login/register.vue')
    },
    {
      //个人中心
      path:'/account',
      name:'myspace',
      component:()=>import('../views/AccountPage/account-page.vue')
    },
    {
      //订单页面
      path:'/order',
      name:'order',
      component:()=>import('../views/OrderPage/order-page.vue'),
    },
    // {
    //   //新建订单页面
    //   path:'/new-order',
    //   name:'new-order',
    //   component:()=>import('../views/OrderPage/new-order.vue'),
    // },
    // {
    //   //查看订单页面
    //   path:'/view-order',
    //   name:'view-order',
    //   component:()=>import('../views/OrderPage/view-order.vue'),
    // },
    // {
    //   //确认订单页面
    //   path:'/confirm-order',
    //   name:'confirm-order',
    //   component:()=>import('../views/OrderPage/confirm-order.vue'),
    // },
    {
      //查看订单页面
      path:'/view-order',
      name:'view-order',
      component:()=>import('../views/OrderPage/view-order.vue'),
    },
    {
      //确认订单页面
      path:'/confirm-order',
      name:'confirm-order',
      component:()=>import('../views/OrderPage/confirm-order.vue'),
    }
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue')
    // }
    // {
    //   path:'/product',
    //   name:'product',
    //   component:()=>import('../views/ProductPage/main-product.vue')
    // },
    // {
    //   path:'/info',
    //   name:'picinfo',
    //   component:()=>import('../views/ProductPage/main-info.vue')
    // }
  ]
})

export default router
